using System;
using System.Collections.Generic;
using System.Text;

namespace SemanticEngine.Apml
{
	public class ApmlDocument : ValidationBase
	{

		#region Properties

		private string _Title;

		public string Title
		{
			get { return _Title; }
			set { _Title = value; }
		}

		private string _Generator = "SemanticEngine.NET";

		public string Generator
		{
			get { return _Generator; }
			set { _Generator = value; }
		}

		private string _UserEmail;

		public string UserEmail
		{
			get { return _UserEmail; }
			set { _UserEmail = value; }
		}

		private DateTime _DateCreated = DateTime.Now;

		public DateTime DateCreated
		{
			get { return _DateCreated; }
			set { _DateCreated = value; }
		}

		private List<ApmlProfile> _Profiles = new List<ApmlProfile>();

		public List<ApmlProfile> Profiles
		{
			get { return _Profiles; }
		}

		public ApmlProfile DefaultProfile
		{
			get
			{
				return Profiles.Find(delegate(ApmlProfile ap)
				{
					return ap.IsDefaultProfile;
				});
			}
		}

		private string _DefaultFrom;

		public string DefaultFrom
		{
			get { return _DefaultFrom; }
			set { _DefaultFrom = value; }
		}

		#endregion

		protected override void Validate()
		{
			AddRule("Profiles", "The ApmlDocument must contain at least one Profile", Profiles.Count == 0);
			AddRule("Title", "The title of the ApmlDocument must be set", string.IsNullOrEmpty(Title));
			
			foreach (ApmlProfile profile in Profiles)
			{
				if (!profile.IsValid)
				{
					AddRule("Profiles", profile.ValidationMessage, true);
					//break;
				}
			}
		}
	}
}
